'use server'
import { get, post, patch, del } from './fetch'


export async function getCampuses({ status, name }) {
  try {
    const campuses = await get('/api/v1/branch-campuses', { status, name })
    return campuses
  } catch (error) {
    throw error
  }
}

export async function getCampusInfo(id) {
  try {
    const campus = await get(`/api/v1/branch-campuses/${id}`)
    return campus
  } catch (error) {
    throw error
  }
}

export async function createCampus(campus) {
  try {
    const newCampus = await post('/api/v1/branch-campuses', campus)
    return newCampus
  } catch (error) {
    throw error
  }
}

export async function updateCampus(campusId, campus) {
  try {
    const updatedCampus = await patch(`/api/v1/branch-campuses/${campusId}`, campus)
    return updatedCampus
  } catch (error) {
    throw error
  }
}


export async function deleteCampus(campusId) {
  try {
    await del(`/api/v1/branch-campuses/${campusId}`)
  } catch (error) {
    throw error
  }
}

export async function getCampusCourts(campusId) {
  try {
    const courts = await get(`/api/v1/branch-campuses/${campusId}/courts`)
    return courts
  } catch (error) {
    throw error
  }
}
